/**
 * @param {number[]} nums
 * @return {number}
 */
var maxSubarraySumCircular = function (nums) {
  let n = nums.length, arr = [], sum = 0, left = 0, right = 0, count = 0
  while (left < n) {
    right = left
    sum = 0
    sum += nums[left]
    count = 0
    while (count < n) {
      right = (right + 1) % n
      sum += nums[right]
      count++
      arr.push(sum)
    }

    left++
  }
  return Math.max(...arr)
};

maxSubarraySumCircular([3, -2, 2, -3])